const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const activeCodeValidate = require('@/middlewares/validateMiddlewares/activeCodeValidate')
const {
  validateSlideCode
} = require('@/middlewares/validateMiddlewares/userValidate')
const activeCodeController = require('@/controller/activeCodeController')
const { verifyAdmin } = require('@/middlewares/validateMiddlewares/verifyAdmin')

const router = new Router()

/**
 * 获取激活码列表
 */
router.get(
  '/list',
  verifyToken(),
  verifyAdmin(),
  activeCodeValidate.listActiveCodeValidate,
  activeCodeController.listActiveCode
)

/**
 * 创建激活码列表
 */
router.post(
  '/create',
  verifyToken(),
  verifyAdmin(),
  activeCodeValidate.createActiveCodeValidate,
  activeCodeController.createActiveCode
)

/**
 * 删除激活码
 */
router.delete(
  '/delete',
  validateSlideCode(),
  verifyToken(),
  verifyAdmin(),
  activeCodeValidate.delActiveCodesValidate,
  activeCodeController.delActiveCodes
)

router.put(
  '/sort',
  verifyToken(),
  verifyAdmin(),
  activeCodeValidate.delActiveCodesValidate,
  activeCodeController.sortActiveCodes
)

/**
 *  激活码激活
 */
module.exports = router
